//
//  CLReplyPostsViewController.m
//  CL1024
//
//  Created by liu nian on 13-4-16.
//  Copyright (c) 2013年 liunian. All rights reserved.
//

#import "CLReplyPostsViewController.h"
#import "CLTextLayoutLabel.h"
#import "CLConst.h"
#import "PrettyKit.h"

@interface CLReplyPostsViewController ()

@end

@implementation CLReplyPostsViewController


- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    UITableView *tableview = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    tableview.delegate = self;
    tableview.dataSource = self;
    self.replyPostsTableView = tableview;
    [tableview release];
    [self.view addSubview:self.replyPostsTableView];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



#pragma mark -
#pragma mark  UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.replyPosts count];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        CLTextLayoutLabel *content = [[[CLTextLayoutLabel alloc] initWithFrame:CGRectZero] autorelease];
        content.tag = 1112;
        content.font = kHSCNBoldFont16;
        content.textColor = [UIColor colorWithHex:0x454545];
        content.lineBreakMode = UILineBreakModeWordWrap;
        content.shadowColor = [UIColor lightGrayColor];
        content.backgroundColor = [UIColor clearColor];
        content.shadowOffset = CGSizeMake(0.1, 0.1);
        content.numberOfLines = 0;
        content.opaque = NO;
        [content setLinesSpacing:8.0f];
        [cell.contentView addSubview:content];
    }
//    cell.textLabel.text = [self.replyPosts objectAtIndex:indexPath.row];
    NSString *content = [self.replyPosts objectAtIndex:indexPath.row];
    CLTextLayoutLabel *contentLabel = (CLTextLayoutLabel *)[cell.contentView viewWithTag:1112];
    CGFloat height = [self getLabelHeight:content];
    [contentLabel setFrame:CGRectMake(10, 10, 305, height)];
    contentLabel.text = content;
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

    CGFloat height = [self getLabelHeight:[self.replyPosts objectAtIndex:indexPath.row]];
    if (height < 60) {
        height = 60;
    }
    return height;
}

-(CGFloat)getLabelHeight:(NSString *)content
{
    //=======计算label所占用的高度======
    CLTextLayoutLabel *cltext = [[CLTextLayoutLabel alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    cltext.text = content;
    cltext.font = kHSCNBoldFont16;
    [cltext setLinesSpacing:8.0f];
    CGFloat height = [cltext getAttributedStringHeight:305];
    [cltext release];
    return height;
}

-(void)dealloc
{
    [_replyPosts release];
    [_replyPostsTableView release];
    [super dealloc];
}

@end
